package cn.wolfcode.trip.admin.controller;


import cn.wolfcode.trip.base.domain.LandmarkDetai;
import cn.wolfcode.trip.base.domain.LandmarkDetailCommend;
import cn.wolfcode.trip.base.service.ILandmarkDetaiService;
import cn.wolfcode.trip.base.service.ILandmarkDetailCommendService;
import cn.wolfcode.trip.base.service.ILmTicketCatalogBigService;
import cn.wolfcode.trip.base.service.ILtCatalogDetailService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("subfieldSpecialSell")
public class SubfieldSpecialSellController {
    @Autowired
    private ILmTicketCatalogBigService lmTicketCatalogBigService;
    @Autowired
    private ILandmarkDetailCommendService landmarkDetailCommendService;
    @Autowired
    private ILtCatalogDetailService ltCatalogDetailService;
    @Autowired
    private ILandmarkDetaiService landmarkDetaiService;

    //list
    @RequestMapping("/Looklist")
    public String Looklist(Long specialSubCommendId,Model model){
        model.addAttribute("specialSubCommends",lmTicketCatalogBigService.getLmTicketCatalogBigByState(1));
        if(specialSubCommendId!=null&&specialSubCommendId!=-1){
            model.addAttribute("list",landmarkDetailCommendService.getCommendByCatalogBigId(specialSubCommendId));
            model.addAttribute("specialSubCommendId",specialSubCommendId);
        }
        return "subfieldSpecialSell/list";
    }

    //三级联动
    @RequestMapping("/getCatalogBigBypId")
    @ResponseBody
    public Object getCatalogBigBypId(Long specialSubCommendId){
        return lmTicketCatalogBigService.getCatalogBigBypId(specialSubCommendId);
    }
    //三级联动
    @RequestMapping("/getCatalogDetailBycbId")
    @ResponseBody
    public Object getCatalogDetailBycbId(Long cbTwoId){
        int icdId = ltCatalogDetailService.getCatalogDetailBycbId(cbTwoId);
        return landmarkDetaiService.getlDetailByicdId(Long.valueOf(icdId));
    }

    @RequestMapping("/insertRelation")
    @ResponseBody
    public Object insertRelation(Long specialSubCommendId,Long ticketId){
        JSONResult result=new JSONResult();
        try {
            landmarkDetailCommendService.insertRelation(specialSubCommendId,ticketId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
